import 'package:flutter/material.dart';

///设置弹性效果
///默认值会减小弹性效果
class CustomAlwaysScrollPhysics extends AlwaysScrollableScrollPhysics {
  final double? stiffness; //弹簧常数(k)
  final double? mass; //弹簧的质量(m)
  final double? ratio; //阻尼

  const CustomAlwaysScrollPhysics({
    this.stiffness,
    this.mass,
    this.ratio,
    ScrollPhysics? parent,
  }) : super(parent: parent);

  @override
  CustomAlwaysScrollPhysics applyTo(ScrollPhysics? ancestor) {
    return CustomAlwaysScrollPhysics(parent: buildParent(ancestor));
  }

  @override
  SpringDescription get spring => SpringDescription.withDampingRatio(
        mass: mass ?? 0.5,
        stiffness: stiffness ?? 300.0, // Increase this value as you wish.
        ratio: ratio ?? 1.1,
      );
}

///设置弹性效果
///默认值会减小弹性效果
class CustomClampingScrollPhysics extends ClampingScrollPhysics {
  final double? stiffness; //弹簧常数(k)
  final double? mass; //弹簧的质量(m)
  final double? ratio; //阻尼

  const CustomClampingScrollPhysics({
    this.stiffness,
    this.mass,
    this.ratio,
    ScrollPhysics? parent,
  }) : super(parent: parent);

  @override
  CustomClampingScrollPhysics applyTo(ScrollPhysics? ancestor) {
    return CustomClampingScrollPhysics(parent: buildParent(ancestor));
  }

  @override
  SpringDescription get spring => SpringDescription.withDampingRatio(
        mass: mass ?? 0.5,
        stiffness: stiffness ?? 300.0, // Increase this value as you wish.
        ratio: ratio ?? 1.1,
      );
}
